package com.observer.demo2.impl;

import java.util.Observable;
import java.util.Observer;
import com.observer.demo2.face.DisplayElement;

/**
 * 另一个观察者
 * 
 * @author dell
 * 
 */
public class OtherDisplay implements Observer, DisplayElement {

	private float result;
	Observable observable;

	public OtherDisplay(Observable observable) {
		this.observable = observable;
		observable.addObserver(this);
	}

	@Override
	public void display() {
		// TODO Auto-generated method stub
		System.out.println("Other display: " + result);
	}

	@Override
	public void update(Observable obs, Object arg) {
		// TODO Auto-generated method stub
		if (obs instanceof WeatherData) {
			WeatherData weatherData = (WeatherData) obs;
			this.result = weatherData.getTemperature()
					* weatherData.getHumidity();
			display();
		}
	}

}
